'''
Author: zhang
Date: 2025-04-02 13:55:41
Description: 
LastEditors: zhang
LastEditTime: 2025-04-02 14:08:04
'''


def generate_cells(bottom_cell, terrain_size):
    x, y = bottom_cell
    width, height = terrain_size

    cells = [(x, y)]  # 先加入底部格子
    left_cells = [(x, y)]  # 存放往左上的格子
    right_cells = []  # 存放往右上的格子

    # 计算往左上的 A 个格子
    cx, cy = x, y
    for _ in range(width - 1):  # 左上移动 width-1 步
        if cy % 2 == 0:  # 偶数行：列和行都减少
            cx -= 1
        cy -= 1
        left_cells.append((cx, cy))

    print(left_cells)  # 3x3 地形
    # 计算 M 中每个格子的右上方向格子
    for lx, ly in left_cells:
        cx, cy = lx, ly
        for _ in range(height - 1):  # 右上移动 height-1 步
            if cy % 2 == 0:  # 偶数行：仅行减少
                cy -= 1
            else:  # 奇数行：行减少，列增加
                cx += 1
                cy -= 1
            right_cells.append((cx, cy))

    # 合并所有格子并去重
    cells.extend(left_cells)
    cells.extend(right_cells)
    return sorted(set(cells))  # 去重并排序


print(generate_cells((1, 4), (2, 3)))  # 3x3 地形
